﻿using Framework.EncryptionDecryptionService.Abstract;
using Framework.EncryptionDecryptionService.Attributes;
using Framework.EncryptionDecryptionService.Enums;
using Framework.EncryptionDecryptionService.Helpers;
using Framework.EncryptionDecryptionService.Models;
using System.Security.Cryptography;

namespace Framework.EncryptionDecryptionService.Achieve
{
    /// <summary>
    /// AES秘钥服务
    /// </summary>
    [Encryption(EncryptionAlgorithm.AES)]
    public class SecretKeyServiceAes : AbsSecretKeyService
    {
        /// <summary>
        /// AES秘钥服务
        /// </summary>
        /// <param name="secretKey">秘钥</param>
        public SecretKeyServiceAes(SecretKeyModel secretKey = null) : base(secretKey)
        {
        }

        internal override SecretKeyModel InitStaticSecretKey()
        {
            using (Aes ase = Aes.Create())
            {
                ase.GenerateKey();
                ase.GenerateIV();
                return new SecretKeyModel(ase.Key.ToBase64String(), ase.IV.ToBase64String());
            }
        }
    }
}
